﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillIcon : MonoBehaviour
{
    public Image Perview;
    public GameObject CoolingMask;
    public AudioSource m_CoolCompleteAudio;
    public Control m_Controle;

    Ship m_Ship;
    bool m_IsReady = true;

    private void Awake()
    {
        m_Controle.OnControleShipChanged.AddListener(OnControleShipChanged);
    }
    void Start()
    {
    }
    void OnControleShipChanged(Ship ship)
    {
        m_Ship = ship;
    }

    // Update is called once per frame
    void Update()
    {
        if (null == m_Ship)
            return;
        float process = 1.0f - Mathf.Clamp(m_Ship.SkillCoolingTimeCount / m_Ship.SkillCoolingTimeMax, 0f, 1f);
        var size = CoolingMask.GetComponent<RectTransform>().sizeDelta;
        size.y = GetComponent<RectTransform>().sizeDelta.y * process;
        CoolingMask.GetComponent<RectTransform>().sizeDelta = size;
        if(process ==0)
        {
            if(m_IsReady == false)
            {
                m_IsReady = true;
                m_CoolCompleteAudio.Play();
            }
        }
        else
        {
            m_IsReady = false;
        }
    }
}
